package com.shizhanzhe.zxbapp.customtask;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.CheckBean;
import com.shizhanzhe.zxbapp.utils.Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by YJ on 2018/10/23.
 */
public class CheckAdapter extends RecyclerView.Adapter<CheckAdapter.ViewHolder> {
    private Context mContext;
    private List<CheckBean.DataBeanX.DataBean> mData = new ArrayList<>();

    public CheckAdapter(Context context) {
        mContext = context;
    }

    public void updateData(int page, List<CheckBean.DataBeanX.DataBean> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            if (page == 1) {
                mData = dataSet;
            } else {
                mData.addAll(dataSet);
            }
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_check, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        final CheckBean.DataBeanX.DataBean dataBean = mData.get(position);
        //1下载  2注册  3其他
        holder.tvPaixu.setText((position+1)+"");
        holder.tvText.setText("提交时间：" + Util.stampToDate(dataBean.getSaddtime() + ""));
        switch (dataBean.getStatus()){
            case 0:
                holder.tv_status.setText("已申请");
                break;
            case 1:
                holder.tv_status.setText("待审核");
                break;
            case 2:
                holder.tv_status.setText("已通过");
                break;
            case 3:
                holder.tv_status.setText("未通过");
                break;
            case 4:
                holder.tv_status.setText("任务超时");
                break;
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mItemClickListener.onItemClick(dataBean);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_paixu)
        TextView tvPaixu;
        @BindView(R.id.tv_text)

        TextView tvText;
        @BindView(R.id.tv_status)
        TextView tv_status;

        @BindView(R.id.ll)
        LinearLayout ll;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    protected ScreenItemListener mItemClickListener;

    public interface ScreenItemListener {
        void onItemClick(CheckBean.DataBeanX.DataBean item);
    }

    public void setScreenItemListener(ScreenItemListener listener) {
        this.mItemClickListener = listener;
    }
}
